﻿using System;
namespace HomeWork2 {
    public interface getS {
        public float getS(); 
    }
    public  class ShapeBase :getS{
        public int lineCount;
        public float B;
        public float A;
        public float S;
        public virtual float getS() { return 0; }
        public virtual bool isShape() { return true; }
    }
    public class Square:ShapeBase,getS {
        public Square(float A,float B,int n) {
            this.A = A;
            this.B = B;
            S = A * B;
            lineCount = n;
        }
        public override float getS() {
            return S;
        }
        public override bool isShape() {
            if (lineCount != 4) { 
                return false;
            }
            return true;
        }
    }
    public class Cube : ShapeBase {
        public Cube(float A,int B,int n)
        {
            this.A = A;
            this.B = B;
            S = A * B;
            lineCount = n;
        }
        public override float getS()
        {
            return S;
        }
        public override bool isShape()
        {
            if (lineCount != 4||A!=B)
            {
                return false;
            }
            return true;
        }
    }
    public class Circle : ShapeBase {
        public float r;
        public Circle(float r,int n){
            this.r = r;
            this.A = r;
            this.B = r;
            this.lineCount = n;
            this.S=r*r*MathF.PI;
        }
        public override float getS() {
            return S;
        }
        public override bool isShape()
        {
            if (lineCount != 0) {
                return false;
            }
            return true;
        }
    }
    public class ShapeTest { 
        public ShapeBase RandomShape() { 
            Random random = new Random();
            int ans=random.Next(1,4);
            switch (ans) {
                case(1):
                    return new Square(3, 4, 4);
                    break;
                case(2):
                    return new Cube(4, 4, 4);
                    break;
                case(3):
                    return new Circle(4, 0);
                    break;
                default:
                    return null;
                    break;

            }
        }
        public static void Main(string[] args) {
            ShapeTest test = new ShapeTest();
            ShapeBase[] shapeArr = new ShapeBase[10];
            float sSum = 0;
            for (int i = 0; i < 10; i++)
            {
                shapeArr[i] = test.RandomShape();
                sSum += shapeArr[i].getS();
                Console.WriteLine("第" + (i+1) + "次的面积是:" + shapeArr[i].getS());
            }
            Console.WriteLine("十个图形总面积是：" + sSum);

        }
    }
}